<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @refresh-change="refreshChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @on-load="onLoad">
      <template slot-scope="{row,type,size}" slot="menu">
        <el-button  icon="el-icon-tickets" :size="size" :type="type"  @click="toLogDetail(row)">日志详情</el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
    import {mapGetters} from "vuex";
    import {getOverviewList} from "@/youan/api/kettle/log";
    export default {
        name: "logOverview",
        data() {
          return {
            loading: true,
            form: {},
            query: {},
            page: {
              pageSize: 10,
              currentPage: 1,
              total: 0
            },
            option:{
              tip: false,
              border: true,
              index: true,
              viewBtn: true,
              dialogType: 'drawer',
              dialogClickModal: false,
              calcHeight: 90,
              searchMenuSpan: 6,
              labelWidth: 150,
              column: [
                {
                  prop: "taskId",
                  display: false,
                  showColumn: false,
                  hide: true
                },
                {
                  label: "定时器任务名称",
                  prop: "taskName",
                  search: true,
                  searchLabelWidth: 120,
                  display: true,
                },
                {
                  label: "已运行次数",
                  prop: "runNum",
                },
                {
                  label: "正在运行数量",
                  prop: "runningNum",
                },
                {
                  label: "已成功数量",
                  prop: "successNum",
                },
                {
                  label: "已失败数量",
                  prop: "errorNum",
                },
                {
                  label: "最近一次运行开始时间",
                  prop: "lastRunTime",
                },
                {
                  label: "最近一次运行成功时间",
                  prop: "lastSuccessTime",
                },
                {
                  label: "最近一次运行失败时间",
                  prop: "lastErrorTime",
                },
              ]
            },
          }
        },
        computed: {
          ...mapGetters(["userInfo", "permission"]),
          permissionList() {
            return {
              addBtn: this.vaildData(this.permission.logOverview_add, false),
              viewBtn: this.vaildData(this.permission.logOverview_view, false),
              delBtn: this.vaildData(this.permission.logOverview_delete, false),
              editBtn: this.vaildData(this.permission.logOverview_edit, false)
            };
          },
        },
        methods: {
          selectionChange(list) {
            this.selectionList = list;
          },
          currentChange(currentPage) {
            this.page.currentPage = currentPage;
          },
          sizeChange(pageSize) {
            this.page.pageSize = pageSize;
          },
          refreshChange() {
            this.onLoad(this.page, this.query);
          },
          onLoad(page, params = {}) {
            this.loading = true;
            getOverviewList(page.currentPage, page.pageSize, Object.assign(params, this.query), this.treeDeptId).then(res => {
              const data = res.data.data;
              this.page.total = data.total;
              this.data = data.records;
              this.loading = false;
              this.selectionClear();
            });
          },
          selectionClear() {
            this.selectionList = [];
            this.$refs.crud.toggleSelection();
          },
          searchReset() {
            this.query = {};
            this.onLoad(this.page);
          },
          searchChange(params, done) {
            this.query = params;
            this.page.currentPage = 1;
            this.onLoad(this.page, params);
            done();
          },
          toLogDetail(row) {
            this.$router.push({
              name: '日志监控',
              params: {taskName: row.taskName}
            });
          },
        },
    }
</script>

<style scoped>

</style>
